package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/payment")
@Tag(name="支付方式管理")
public class PaymentTypeController {

    @Autowired
    private PaymentTypeService paymentTypeService;


    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> selectAllPaymentType(){
        List<PaymentType> paymentTypeList = paymentTypeService.list();
        return Result.ok(paymentTypeList);
    }

    @Operation(summary = "跟据id删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentType(@RequestParam Long id){

        boolean byId = paymentTypeService.removeById(id);
        return Result.ok(byId);
    }


    @Operation(summary = "增加或修改支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType){

        boolean savedOrUpdate = paymentTypeService.saveOrUpdate(paymentType);
        return  Result.ok(savedOrUpdate);
    }
}
